package com.xfd.business.user.web;

import java.util.Calendar;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xfd.business.user.entity.User;


/**
 * @since 2016年1月15日 上午10:44:08
 * @author xjh
 */
@Controller
@RequestMapping("/user")
public class UserController {
	
	private static final Logger logger = LogManager.getLogger(UserController.class);
	

	/**
	 * JSON 格式的数据，直接返回对象。
	 * @param userId 用户ID
	 * @return User
	 */
	@RequestMapping(value="/{userId}.json", method = RequestMethod.GET)
	@ResponseBody
	public User getUser(@PathVariable String userId){
		logger.debug(this);
		logger.debug("userId is {}",userId);
		return new User();
	}
	
	/**
	 * 文本返回
	 * @param userId 用户ID
	 * @return String
	 */
	@RequestMapping(value="/test/{userId}", method = RequestMethod.GET)
	@ResponseBody
	public String getUserTextDesc(@PathVariable String userId){
		logger.debug("userId is {}",userId);
		return new User().toString();
	}
	
	/**
	 * 跳转到页面
	 * @return String
	 */
	@RequestMapping(value="/", method = RequestMethod.GET)
	public String index(Model m){
		m.addAttribute("date", String.format("%tF %<tT", Calendar.getInstance()));
		logger.debug("跳转到一个页面");
		return "/index";
	}
	
}
